home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / arc / xadmasterdev.lha / xad / Sources / clients / TR-DOS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-20  |  5.3 KB  |  187 lines

  1. #ifndef XADMASTER_TRD_C
  2. #define XADMASTER_TRD_C
  3.  
  4. /* Programmheader
  5.  
  6.         Name:           TR-DOS.c
  7.         Main:           xadmaster
  8.         Versionstring:  $VER: TR-DOS.c 1.1 (28.07.2002)
  9.         Author:         AmiS (amis@amiga.org.ru)
  10.         Distribution:   GPL
  11.         Description:    TR-DOS FS this is filesystem client for TR-DOS disk images.
  12.  
  13.  1.0   23.07.02 : first version
  14.  1.1   28.07.02 : fixed some little problems (SDI)
  15. */
  16.  
  17. #include <proto/xadmaster.h>
  18. #include "SDI_compiler.h"
  19. #include "ConvertE.c"
  20. #include "xadSPrintF.c"
  21. #include "xadCPU.h"
  22.  
  23. #ifndef XADMASTERFILE
  24. #define TRD_Client              FirstClient
  25. #define NEXTCLIENT              0
  26. #define XADMASTERVERSION        11
  27. UBYTE version[] = "$VER: TR-DOS 1.1 (28.07.2002)" CPUTEXT " GPL by AmiS";
  28. #endif
  29. #define TRD_VERSION             1
  30. #define TRD_REVISION            1
  31.  
  32. /*
  33. struct TRD_File
  34. {
  35.   char Name[8];
  36.   UBYTE Type;
  37.   UWORD Start;
  38.   UWORD Length;
  39.   UBYTE Sectors;
  40.   UBYTE FirstSector;
  41.   UBYTE Track;
  42. } fl[128];
  43.  
  44. struct ControlSector
  45. {
  46.   UBYTE Zero;
  47.   UBYTE Reserv1[224];
  48.   UBYTE FirstFreeSector;
  49.   UBYTE TrackFirstFreeSector;
  50.   UBYTE DiskType;
  51.   UBYTE FilesCount;
  52.   UWORD FreeSectorsCount;
  53.   UBYTE TRDOS_ID;
  54.   UBYTE Reserv2[2];
  55.   UBYTE Reserv3[9];
  56.   UBYTE Reserv4;
  57.   UBYTE FeleteFilesCount;
  58.   UBYTE DiskName[8];
  59.   UBYTE Reserv5[3];
  60. } cs;
  61. */
  62.  
  63. #ifdef DEBUG
  64. #include <proto/dos.h>
  65. #define DOSBase xadMasterBase->xmb_DOSBase
  66. #endif
  67.  
  68. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  69. ASM(LONG) TRD_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  70. REG(a6, struct xadMasterBase *xadMasterBase))
  71. { CPUCHECK {
  72.   UBYTE fl[16], cs[256];
  73.   LONG err;
  74.  
  75.   if(ai->xai_InSize == 655360)
  76.   {
  77.     if(!(err = xadHookAccess(XADAC_INPUTSEEK, 256*8, NULL, ai)))
  78.     {
  79.       if(!(err = xadHookAccess(XADAC_READ, 256, cs, ai)))
  80.       {
  81. #ifdef DEBUG
  82.   Printf("TR-DOS:\n");
  83.   Printf("Inputfile size=%ld\n", ai->xai_InSize);
  84.   Printf("Control Secor:\n");
  85.   Printf("Zero = %ld\n", cs[0]);
  86.   Printf("FirstFreeSector = %ld\n", cs[1+224]);
  87.   Printf("TrackFirstFreeSector = %ld\n", cs[1+224+1]);
  88.   Printf("DiskType = %ld\n", cs[1+224+1+1]);
  89.   Printf("FilesCount = %ld\n", cs[1+224+1+1+1]);
  90.   Printf("FreeSectorsCount = %ld\n", EndGetI16(&(cs[1+224+1+1+1+1])));
  91.   Printf("TRDOS_ID = %ld\n", cs[1+224+1+1+1+1+2]);
  92. #endif
  93.  
  94.         if(cs[1+224+1+1+1+1+2] == 0x10 && cs[1+224+1+1] == 0x16)
  95.         {
  96.           if(!(err = xadHookAccess(XADAC_INPUTSEEK, -(256*8+256), NULL, ai)))
  97.           {
  98.             ULONG filecount;
  99.             struct xadFileInfo *fi;
  100.             UWORD CheckSum;
  101.  
  102.             for(filecount=1; !err && filecount<=cs[1+224+1+1+1]; filecount++)
  103.             {
  104.               if(!(err = xadHookAccess(XADAC_READ, 16, fl, ai)))
  105.               {
  106.                 if((fi = (struct xadFileInfo *)xadAllocObject(XADOBJ_FILEINFO,
  107.                 XAD_OBJPRIVINFOSIZE, 17, XAD_OBJNAMESIZE, 8+1+2+1,
  108.                 XAD_OBJCOMMENTSIZE, 10, TAG_DONE)))
  109.                 {
  110.                   ULONG i;
  111.                   fi->xfi_EntryNumber = filecount;
  112.                   fi->xfi_Flags = XADFIF_NODATE|XADFIF_SEEKDATAPOS
  113.                                   |XADFIF_EXTRACTONBUILD;
  114.                   xadConvertDates(XAD_DATECURRENTTIME, 1, XAD_GETDATEXADDATE,
  115.                   &fi->xfi_Date, TAG_DONE);
  116.  
  117.                   fi->xfi_Size = fi->xfi_CrunchSize = fl[13]*256+17;
  118.                   fi->xfi_DataPos = fl[14]*256+fl[15]*16*256;
  119.  
  120.                   /* Fill Header */
  121.                   xadCopyMem(fl, (UBYTE *)(fi->xfi_PrivateInfo), 13);
  122.                   ((UBYTE *)(fi->xfi_PrivateInfo))[13] = 0;
  123.                   ((UBYTE *)(fi->xfi_PrivateInfo))[14] = fl[13];
  124.                   CheckSum=0;
  125.                   for(i=0; i<=14; i++)
  126.                     CheckSum += (((UBYTE *)(fi->xfi_PrivateInfo))[i] * 257) + i;
  127.                   ((UBYTE *)(fi->xfi_PrivateInfo))[16] = CheckSum>>8;
  128.                   ((UBYTE *)(fi->xfi_PrivateInfo))[15] = CheckSum&0x00ff;
  129.  
  130.                   SPrintF(xadMasterBase->xmb_SysBase, fi->xfi_Comment, "%ld",
  131.                   EndGetI16(&(fl[11])));
  132.                   SPrintF(xadMasterBase->xmb_SysBase, fi->xfi_FileName,
  133.                   "%.8s.!%lc", fl, fl[8]);
  134.  
  135.                   err = xadAddFileEntry(fi, ai, XAD_SETINPOS, ai->xai_InPos,
  136.                   TAG_DONE);
  137.                 }
  138.                 else err = XADERR_NOMEMORY;
  139.               }
  140.             }
  141.           }
  142.         }
  143.         else err = XADERR_FILESYSTEM;
  144.       }
  145.     }
  146.   }
  147.   else
  148.     err = XADERR_FILESYSTEM;
  149.  
  150.   if(err && ai->xai_FileInfo)
  151.   {
  152.     ai->xai_Flags |= XADAIF_FILECORRUPT;
  153.     ai->xai_LastError = err;
  154.     err = XADERR_OK;
  155.   }
  156.  
  157.   return err;
  158. }}
  159.  
  160. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  161. ASM(LONG) TRD_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  162. REG(a6, struct xadMasterBase *xadMasterBase))
  163. {
  164.   LONG err;
  165.   if(!(err = xadHookAccess(XADAC_WRITE, 17, ai->xai_CurFile->xfi_PrivateInfo, ai)))
  166.   {
  167.     err = xadHookAccess(XADAC_COPY, ai->xai_CurFile->xfi_Size-17, NULL, ai);
  168.   }
  169.   return err;
  170. }
  171.  
  172. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  173. const struct xadClient TRD_Client =
  174. {
  175.   NEXTCLIENT, XADCLIENT_VERSION, XADMASTERVERSION, TRD_VERSION, TRD_REVISION,
  176.   0,
  177.   XADCF_FILESYSTEM | XADCF_FREEFILEINFO,
  178.   0,
  179.   "TR-DOS FS",
  180.   (BOOL (*)()) NULL,
  181.   (LONG (*)()) TRD_GetInfo,
  182.   (LONG (*)()) TRD_UnArchive,
  183.   (void (*)()) NULL,
  184. };
  185.  
  186. #endif /* XADASTER_TRD_C */
  187.